#include "stdafx.h"
#include "cGameController.h"
#include"cLoginDialog.h"
#include"cRegisterDialog.h"
#include"cQuitDialog.h"
#include"cMusicControlDialog.h"

cGameController::cGameController()
{
	m_pGameView = nullptr;
	m_IsOpenMusic = true;
	m_gameVolume = 500;
	m_status = Select_Status;
}

cGameController::~cGameController()
{
	delete m_pGameView;
	m_pGameView = nullptr;
}

int cGameController::OnTimer(int id, int iParam, string str)
{
	switch (id)
	{
	case Time_Draw:
		m_pGameView->DrawView();
		break;
	default:
		break;
	}
	return 1;
}

void cGameController::StartGame(const HWND & hWnd, const HINSTANCE& hInstance)
{
	m_status = Select_Status;
	m_pGameView = new cGameView(hWnd, hInstance);
	m_pGameView->UpdateGameStatus(m_status);
	AddTimer(Time_Draw, 50);
	m_GameMusic.PlayBgSound(L"Music/bg2.mp3");
	m_GameMusic.SetMusicVolume(m_gameVolume);
}

void cGameController::LButtonDown()
{
	tagPOINT tg;
	GetCursorPos(&tg);
	ScreenToClient(m_pGameView->GethWnd(), &tg);
	if (tg.x>385 && tg.x<385 + 128 && tg.y>170 && tg.y<170 + 32)
	{
		m_pGameView->SetBtnPress(0);
		cLoginDialog login(m_pGameView->GethWnd(), m_pGameView->GetInstance(), 500, 400);
		login.Show();
		if (login.GetIsLogin())
		{
			m_status = Play_Status;
			m_pGameView->UpdateGameStatus(Play_Status);
		}
		m_pGameView->ChageAllBtnStatus();
	}
	else if (tg.x>385 && tg.x<385 + 128 && tg.y>170 + 90 && tg.y<170 + 90 + 32)
	{
		m_pGameView->SetBtnPress(1);
		cRegisterDialog Register(m_pGameView->GethWnd(), m_pGameView->GetInstance(), 500, 400);
		Register.Show();
		m_pGameView->ChageAllBtnStatus();
	}
	else if (tg.x>385 && tg.x<385 + 128 && tg.y>170 + 90 * 2 && tg.y<170 + 90*2 + 32)
	{
		m_pGameView->SetBtnPress(2);
		cQuitDialog quit(m_pGameView->GethWnd(), m_pGameView->GetInstance(), 300, 250);
		quit.Show();
		if (quit.GetIsQuit())
		{
			Sleep(300);
			PostQuitMessage(0);
		}
		m_pGameView->ChageAllBtnStatus();
	}
	else if (tg.x > 385 && tg.x < 385 + 128 && tg.y>170 + 90*3 && tg.y < 170 + 90*3 + 32)
	{
		m_pGameView->SetBtnPress(3);
		cMusicControlDialog MusicDialog(m_pGameView->GethWnd(), m_pGameView->GetInstance(), 300, 200);
		MusicDialog.SetIsOpen(m_IsOpenMusic);
		MusicDialog.SetVolume(m_gameVolume / 10);
		MusicDialog.Show();
		if (MusicDialog.GetIsClickOk())
		{
			if (MusicDialog.GetIsOpen())
			{
				if (!m_IsOpenMusic)
				{
					m_GameMusic.PlayBgSound(L"Music/bg2.mp3");
					m_IsOpenMusic = true;
				}
				m_gameVolume = MusicDialog.GetVolume() * 10;
				m_GameMusic.SetMusicVolume(m_gameVolume);
			}
			else
			{
				if (m_IsOpenMusic)
				{
					m_GameMusic.StopBgSound();
					m_IsOpenMusic = false;
				}
			}
		}
		m_pGameView->ChageAllBtnStatus();
	}
	else if (tg.x>550&&tg.x<612&&tg.y>60&&tg.y<105)
	{
		m_pGameView->ChageExtraStatus();
	}
}

void cGameController::LButtonUp()
{
	m_pGameView->ChageAllBtnStatus();
}

void cGameController::RButtonDown()
{

}

void cGameController::RButtonUp()
{
	
}

void cGameController::KeyDown(const WPARAM & wParam)
{
}

void cGameController::KeyUp(const WPARAM & wParam)
{
}

